# coding=utf-8
__author__ = 'liubin'

def solution(A):
    # write your code in Python 2.7
    length = len(A)
    stay = []
    for i in xrange(length):
        if i == 0:
            if A[i] == A[i+1]:
                pass
            else:
                stay.append((i,A[i]))
        elif i == length - 1:
            if A[i] == A[i-1]:
                pass
            else:
                stay.append((i, A[i]))
        else:
            if A[i] == A[i+1] or A[i] == A[i-1]:
                pass
            else:
                stay.append((i, A[i]))
    print(stay)
    selected = None
    if len(stay) == 0:
        selected == 0
    for i in xrange(len(stay)):
        if stay[i][0] == 0 and len(stay) > 1:
            pass
        elif stay[i][0] == 0:
            selected = stay[i][0]
        elif stay[i][0] >0 and stay[i][0]< length-1:
            selected = stay[i][0]
            break
        elif stay[i][0] == length-1 and selected is None:
            selected = stay[i][0]
    print(selected)
    A[selected] = 1 if A[selected] == 0 else 0
    print(A)
    count = 0
    for i in xrange(length):
        if i < length -1:
            if A[i] == A[i+1]:
                count = count + 1
    return count


print(solution([1, 1, 0, 1, 0, 0, 1, 1]))